﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.IO;
using IndicoInterface;

namespace t_DeepTalkRenderServiceLib
{
    internal static class Utils
    {
        private static ServiceHost hostDTDBService, hostDTDBRender;

        /// <summary>
        /// Start the service running in the current host
        /// </summary>
        public static void StartMainService()
        {
            hostDTDBService = new ServiceHost(typeof(DeepTalkDBSerice.DTDBService));
            hostDTDBService.Open();
            hostDTDBRender = new ServiceHost(typeof(DeepTalkDBSerice.DTRender));
            hostDTDBRender.Open();
        }

        /// <summary>
        /// Shut down the service running in this host.
        /// </summary>
        public static void ShutdownMainService()
        {
            hostDTDBService.Close();
            hostDTDBService = null;
            hostDTDBRender.Close();
            hostDTDBRender = null;
        }

        /// <summary>
        /// Submit a talk for rendering.
        /// </summary>
        /// <param name="p"></param>
        public static void SubmitTalk(string url)
        {
            StringWriter wr = new StringWriter();
            AgendaInfo ai = new AgendaInfo(url);
            ai.Seralize(wr);

            using (var rc = new t_DeepTalkRenderServiceLib.DTDBService.DTDBClient())
            {
                rc.SubmitNewTalk(wr.ToString(), "No title yet", DateTime.Now);
            }
        }
    }
}
